package eee.xiang.cloud_learning;

import eee.xiang.cloud_learning.bean.entity.TAddress;
import eee.xiang.cloud_learning.bean.entity.TUser;
import eee.xiang.cloud_learning.service.ScheduleThreadService;
import eee.xiang.cloud_learning.service.ShardDataService;
import eee.xiang.cloud_learning.service.SubClasA;
import eee.xiang.cloud_learning.service.SubClasB;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author x-yin
 * @Date 2019/8/28
 */
@RestController
@RequestMapping("/home")
public class HomeController implements ApplicationListener {

    @Autowired
    private ScheduleThreadService scheduleThreadService;

    @Autowired
    private ShardDataService shardDataService;

    @Autowired
    private SubClasA subClasA;

    @Autowired
    private SubClasB subClasB;


    @RequestMapping("/testScheduleStart")
    public String testScheduleStart(){

        scheduleThreadService.startSchedule();

        return "没事的啦";
    }


    @RequestMapping("/testScheduleStop")
    public String testScheduleStop(){

        scheduleThreadService.stopSchedule();

        return "没事的啦";
    }

    @RequestMapping("/shardData")
    public String testShardData(){

        TUser user = new TUser();
        user.setId(11111111111L);
        user.setCityId(11111111);
        user.setName("刘备");
        user.setSex(1);
        user.setCreateTime(new Date());

        TUser user1 = new TUser();
        user1.setId(111111121111L);
        user1.setCityId(2222222);
        user1.setName("王二");
        user1.setSex(2);
        user1.setCreateTime(new Date());

        TUser user3 = new TUser();
        user3.setId(11111113111L);
        user3.setCityId(11111111);
        user3.setName("刘梅梅");
        user3.setSex(2);
        user3.setCreateTime(new Date());

        int i = shardDataService.saveUser(user);
        int i1 = shardDataService.saveUser(user1);
        int i3 = shardDataService.saveUser(user3);

        TAddress address = new TAddress();
        address.setId(111111111L);
        address.setLit(11111111);
        address.setName("北京跨国际");
        address.setPid("888888888");

        TAddress address1 = new TAddress();
        address1.setId(111111111L);
        address1.setLit(222222222);
        address1.setName("南湾山嘎达");
        address1.setPid("9999999999");

        int t = shardDataService.saveAdress(address);
        int t1 = shardDataService.saveAdress(address1);

        return "青山湖";
    }


    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        subClasA.method();
        subClasB.method();
        System.out.println(subClasA.desc.toString());
    }
}
